package _98GUI多线程;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;

public class MyFrame extends JFrame{

	public MyFrame() 
	{
		this.setLayout(null);
		
		JButton btn1 = new JButton("测试1");
		btn1.setBounds(0, 0, 100, 50);
		
		JButton btn2 = new JButton("测试2");
		btn2.setBounds(100, 0, 100, 50);
		ImageIcon icon = new ImageIcon("images/walkright1.png");
		JLabel label = new JLabel(icon);
		label.setBounds(50, 150, 100, 100);
		
		this.add(btn1);
		this.add(btn2);
		this.add(label);
		
		
		btn1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				
				// 创建一个子线程
				Thread t = new Thread(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						for(int i=0;i<100;i++)
						{
							label.setBounds((int)(label.getBounds().getX()+5), 150, 100, 100);
							try {
								Thread.sleep(100);
							} catch (InterruptedException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
					}
				});
				// 启动它
//				t.start();
				
				

				
			}
		});
		
	
	}
}
